<script>

import * as echarts from 'echarts';
export default {
  name: 'VisualizationFour',
  data() {
    return{

    }
  },
  mounted() {
    this.getData();
  },
  methods: {
    getData() {
      this.$axios.get('/api/vis/data2', {

      }).then(res =>{
        if(res.data.code === 20041) {
          let data1 = [];
          let data2 = [];
          for (let i = 0; i < res.data.data.length; i++) {
            let data=  res.data.data[i]["column1"];
            let list_1 = data.split("-");
            if(list_1[1] === "01" && list_1[2] !== "39") {
              data1.push(
                  list_1[2]
              );
              data2.push(
                  res.data.data[i]["column2"]
              );
            }
          }
          this.init(data1, data2);
        }
      }).catch(error =>{
        this.open4(error);
      })
    },
    open4(msg) {
      this.$notify.error({
        title: msg,
        message: '这是一条错误的提示消息'
      });
    },
    init(data1, data2) {
      var chartDom = document.getElementById('main6');
      var myChart = echarts.init(chartDom);
      var option;

      option = {
        title: {
          text: '2023年1月份平均压强'
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross',
            label: {
              backgroundColor: '#6a7985'
            }
          }
        },
        legend: {
          data: ['压强/百帕']
        },
        toolbox: {
          feature: {
            saveAsImage: {}
          }
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: [
          {
            type: 'category',
            boundaryGap: false,
            data: data1
          }
        ],
        yAxis: [
          {
            type: 'value'
          }
        ],
        series: [
          {
            name: '压强/百帕',
            type: 'line',
            stack: 'Total',
            areaStyle: {},
            emphasis: {
              focus: 'series'
            },
            data: data2
          }
        ]
      };

      option && myChart.setOption(option);
    }
  }

}
</script>

<template>
  <div id="main6"></div>
</template>

<style scoped>
#main6 {
  width: 100%;
  height: 100%;
}
</style>